package com.ynny.controller;

import com.ynny.dao.R;
import com.ynny.dao.User;
import com.ynny.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/register")
    public R register(@RequestBody User user){
        //数据校验  -----》写在controller层
        if (user.getUsername().equals("") || user.getPassword().equals("")
                ||user.getIdentity().equals("")){

            return R.fail(221,"用户名密码或身份不能为空");
        }
        //注册功能

        int res = userService.register(user);

        if (res == 205){
            return R.fail(205,"用户名已经存在");

        }
        user.setPassword(null);
        return R.ok(user);


    }
}
